<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小红书封面图生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .header {
            text-align: center;
            margin-bottom: 40px;
        }
        
        .header h1 {
            color: #333;
            font-size: 2.5em;
            margin-bottom: 10px;
            background: linear-gradient(45deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .main-content {
            display: grid;
            grid-template-columns: 1fr 400px;
            gap: 40px;
            align-items: start;
        }
        
        .form-section {
            background: #f8f9fa;
            padding: 30px;
            border-radius: 15px;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #333;
        }
        
        .form-group input,
        .form-group textarea,
        .form-group select {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e9ecef;
            border-radius: 10px;
            font-size: 14px;
            transition: all 0.3s ease;
        }
        
        .form-group input:focus,
        .form-group textarea:focus,
        .form-group select:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .form-group textarea {
            height: 80px;
            resize: vertical;
        }
        
        .color-inputs {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .color-input {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .color-input input[type="color"] {
            width: 40px;
            height: 40px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
        }
        
        .template-selector {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 15px;
            margin-top: 10px;
        }
        
        .template-option {
            padding: 15px;
            border: 2px solid #e9ecef;
            border-radius: 10px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            background: white;
        }
        
        .template-option:hover,
        .template-option.selected {
            border-color: #667eea;
            background: #f0f4ff;
        }
        
        .generate-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 20px;
        }
        
        .generate-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        
        .preview-section {
            position: sticky;
            top: 20px;
        }
        
        .preview-container {
            background: #fff;
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            border: 1px solid #e9ecef;
        }
        
        .cover-preview {
            width: 400px;
            height: 500px;
            position: relative;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        
        .cover-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            background: rgba(0,0,0,0.1);
        }
        
        .brand-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .brand-logo {
            width: 30px;
            height: 30px;
            background: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            color: #667eea;
            font-size: 14px;
        }
        
        .brand-name {
            font-size: 14px;
            opacity: 0.9;
        }
        
        .read-indicator {
            font-size: 12px;
            opacity: 0.8;
        }
        
        .main-title {
            padding: 20px;
            font-size: 28px;
            font-weight: bold;
            line-height: 1.3;
            text-align: left;
            flex-grow: 1;
            display: flex;
            align-items: center;
        }
        
        .tags {
            padding: 0 20px 10px;
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }
        
        .tag {
            background: rgba(255,255,255,0.2);
            padding: 4px 12px;
            border-radius: 15px;
            font-size: 12px;
            border: 1px solid rgba(255,255,255,0.3);
        }
        
        .visual-content {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            background: rgba(255,255,255,0.1);
            margin: 0 20px;
            border-radius: 15px;
            backdrop-filter: blur(10px);
        }
        
        .visual-placeholder {
            text-align: center;
            opacity: 0.8;
        }
        
        .bottom-text {
            padding: 20px;
            text-align: center;
            font-size: 14px;
            line-height: 1.4;
            background: rgba(0,0,0,0.1);
        }
        
        .download-section {
            padding: 20px;
            text-align: center;
            background: #f8f9fa;
        }
        
        .download-btn {
            background: #28a745;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        
        .download-btn:hover {
            background: #218838;
            transform: translateY(-1px);
        }
        
        @media (max-width: 768px) {
            .main-content {
                grid-template-columns: 1fr;
                gap: 20px;
            }
            
            .cover-preview {
                width: 100%;
                max-width: 400px;
                margin: 0 auto;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>小红书封面图生成器</h1>
            <p>一键生成专业的小红书封面图片</p>
        </div>
        
        <div class="main-content">
            <div class="form-section">
                <div class="form-group">
                    <label>账号名称</label>
                    <input type="text" id="brandName" placeholder="请输入您的账号名称" value="IN-Power">
                </div>
                
                <div class="form-group">
                    <label>主标题</label>
                    <textarea id="mainTitle" placeholder="输入吸引人的主标题">建议大家尽早培养自己「想到，就去做」的心态</textarea>
                </div>
                
                <div class="form-group">
                    <label>标签（用逗号分隔）</label>
                    <input type="text" id="tags" placeholder="成事心法,行动力,时间管理" value="成事心法,行动力">
                </div>
                
                <div class="form-group">
                    <label>底部文案</label>
                    <textarea id="bottomText" placeholder="输入总结性文字或金句">人不是因为有高能量感才行动的，而是因为行动才有高能量感的。</textarea>
                </div>
                
                <div class="form-group">
                    <label>可视化内容类型</label>
                    <select id="visualType">
                        <option value="comparison">对比图表</option>
                        <option value="process">流程图</option>
                        <option value="chart">数据图表</option>
                        <option value="illustration">插画图解</option>
                        <option value="timeline">时间轴</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label>配色方案</label>
                    <div class="color-inputs">
                        <div class="color-input">
                            <input type="color" id="primaryColor" value="#667eea">
                            <span>主色调</span>
                        </div>
                        <div class="color-input">
                            <input type="color" id="secondaryColor" value="#764ba2">
                            <span>辅助色</span>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label>模板风格</label>
                    <div class="template-selector">
                        <div class="template-option selected" data-template="modern">
                            <div>🎨</div>
                            <div>现代简约</div>
                        </div>
                        <div class="template-option" data-template="gradient">
                            <div>🌈</div>
                            <div>渐变风格</div>
                        </div>
                        <div class="template-option" data-template="minimal">
                            <div>⚪</div>
                            <div>极简风格</div>
                        </div>
                    </div>
                </div>
                
                <button class="generate-btn" onclick="generateCover()">
                    🎯 生成封面图
                </button>
            </div>
            
            <div class="preview-section">
                <div class="preview-container">
                    <div class="cover-preview" id="coverPreview">
                        <div class="cover-header">
                            <div class="brand-info">
                                <div class="brand-logo" id="brandLogo">IP</div>
                                <div class="brand-name" id="previewBrandName">IN-Power</div>
                            </div>
                            <div class="read-indicator">右滑阅读 ></div>
                        </div>
                        
                        <div class="main-title" id="previewTitle">
                            建议大家尽早培养自己<br>「想到，就去做」的心态
                        </div>
                        
                        <div class="tags" id="previewTags">
                            <span class="tag">成事心法</span>
                            <span class="tag">行动力</span>
                        </div>
                        
                        <div class="visual-content">
                            <div class="visual-placeholder" id="visualContent">
                                <div style="font-size: 48px; margin-bottom: 10px;">🧠 ➡️ 💪</div>
                                <div>Thinker → Doer</div>
                            </div>
                        </div>
                        
                        <div class="bottom-text" id="previewBottomText">
                            人不是因为有高能量感才行动的，而是因为行动才有高能量感的。
                        </div>
                    </div>
                    
                    <div class="download-section">
                        <button class="download-btn" onclick="downloadCover()">
                            📥 下载封面图
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 引入html2canvas库 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
    
    <script>
        let currentTemplate = 'modern';
        
        // 实时预览更新
        document.getElementById('brandName').addEventListener('input', updatePreview);
        document.getElementById('mainTitle').addEventListener('input', updatePreview);
        document.getElementById('tags').addEventListener('input', updatePreview);
        document.getElementById('bottomText').addEventListener('input', updatePreview);
        document.getElementById('primaryColor').addEventListener('change', updateColors);
        document.getElementById('secondaryColor').addEventListener('change', updateColors);
        document.getElementById('visualType').addEventListener('change', updateVisual);
        
        // 模板选择
        document.querySelectorAll('.template-option').forEach(option => {
            option.addEventListener('click', function() {
                document.querySelectorAll('.template-option').forEach(o => o.classList.remove('selected'));
                this.classList.add('selected');
                currentTemplate = this.dataset.template;
                updateTemplate();
            });
        });
        
        function updatePreview() {
            const brandName = document.getElementById('brandName').value || 'IN-Power';
            const mainTitle = document.getElementById('mainTitle').value || '请输入标题';
            const tags = document.getElementById('tags').value.split(',').filter(tag => tag.trim());
            const bottomText = document.getElementById('bottomText').value || '';
            
            document.getElementById('previewBrandName').textContent = brandName;
            document.getElementById('brandLogo').textContent = brandName.substring(0, 2).toUpperCase();
            document.getElementById('previewTitle').innerHTML = mainTitle.replace(/\n/g, '<br>');
            document.getElementById('previewBottomText').textContent = bottomText;
            
            const tagsContainer = document.getElementById('previewTags');
            tagsContainer.innerHTML = '';
            tags.forEach(tag => {
                if (tag.trim()) {
                    const tagElement = document.createElement('span');
                    tagElement.className = 'tag';
                    tagElement.textContent = tag.trim();
                    tagsContainer.appendChild(tagElement);
                }
            });
        }
        
        function updateColors() {
            const primaryColor = document.getElementById('primaryColor').value;
            const secondaryColor = document.getElementById('secondaryColor').value;
            const preview = document.getElementById('coverPreview');
            
            preview.style.background = `linear-gradient(135deg, ${primaryColor} 0%, ${secondaryColor} 100%)`;
        }
        
        function updateVisual() {
            const visualType = document.getElementById('visualType').value;
            const visualContent = document.getElementById('visualContent');
            
            const visuals = {
                comparison: '<div style="font-size: 48px; margin-bottom: 10px;">🧠 ➡️ 💪</div><div>Thinker → Doer</div>',
                process: '<div style="font-size: 48px; margin-bottom: 10px;">📋 → 🎯 → ✅</div><div>Plan → Action → Result</div>',
                chart: '<div style="font-size: 48px; margin-bottom: 10px;">📊</div><div>数据可视化图表</div>',
                illustration: '<div style="font-size: 48px; margin-bottom: 10px;">🎨</div><div>概念插画图解</div>',
                timeline: '<div style="font-size: 48px; margin-bottom: 10px;">⏰</div><div>时间轴展示</div>'
            };
            
            visualContent.innerHTML = visuals[visualType] || visuals.comparison;
        }
        
        function updateTemplate() {
            const preview = document.getElementById('coverPreview');
            const primaryColor = document.getElementById('primaryColor').value;
            const secondaryColor = document.getElementById('secondaryColor').value;
            
            switch(currentTemplate) {
                case 'modern':
                    preview.style.background = `linear-gradient(135deg, ${primaryColor} 0%, ${secondaryColor} 100%)`;
                    break;
                case 'gradient':
                    preview.style.background = `linear-gradient(45deg, ${primaryColor}, ${secondaryColor}, #ff6b6b, #4ecdc4)`;
                    break;
                case 'minimal':
                    preview.style.background = `linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%)`;
                    preview.style.color = '#333';
                    break;
            }
        }
        
        function generateCover() {
            updatePreview();
            updateColors();
            updateVisual();
            
            // 添加生成动画效果
            const preview = document.getElementById('coverPreview');
            preview.style.transform = 'scale(1.05)';
            setTimeout(() => {
                preview.style.transform = 'scale(1)';
            }, 300);
            
            // 显示成功提示
            showNotification('✅ 封面图生成成功！', 'success');
        }
        
        async function downloadCover() {
            const preview = document.getElementById('coverPreview');
            const downloadBtn = document.querySelector('.download-btn');
            
            // 更新按钮状态
            downloadBtn.textContent = '🔄 生成中...';
            downloadBtn.disabled = true;
            
            try {
                const canvas = await html2canvas(preview, {
                    width: 800,
                    height: 1000,
                    scale: 2, // 提高清晰度
                    backgroundColor: null,
                    useCORS: true
                });
                
                // 创建下载链接
                const link = document.createElement('a');
                link.download = `小红书封面_${new Date().getTime()}.png`;
                link.href = canvas.toDataURL('image/png');
                
                // 触发下载
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                
                showNotification('🎉 图片下载成功！', 'success');
                
            } catch (error) {
                console.error('下载失败:', error);
                showNotification('❌ 下载失败，请重试', 'error');
            } finally {
                // 恢复按钮状态
                downloadBtn.textContent = '📥 下载封面图';
                downloadBtn.disabled = false;
            }
        }
        
        function showNotification(message, type = 'info') {
            // 创建通知元素
            const notification = document.createElement('div');
            notification.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                padding: 15px 20px;
                border-radius: 8px;
                color: white;
                font-weight: 600;
                z-index: 10000;
                box-shadow: 0 4px 12px rgba(0,0,0,0.15);
                transform: translateX(100%);
                transition: transform 0.3s ease;
            `;
            
            // 设置颜色
            const colors = {
                success: '#28a745',
                error: '#dc3545',
                info: '#17a2b8'
            };
            notification.style.backgroundColor = colors[type] || colors.info;
            notification.textContent = message;
            
            document.body.appendChild(notification);
            
            // 显示动画
            setTimeout(() => {
                notification.style.transform = 'translateX(0)';
            }, 100);
            
            // 自动消失
            setTimeout(() => {
                notification.style.transform = 'translateX(100%)';
                setTimeout(() => {
                    document.body.removeChild(notification);
                }, 300);
            }, 3000);
        }
        
        // 添加键盘快捷键
        document.addEventListener('keydown', function(e) {
            if (e.ctrlKey || e.metaKey) {
                switch(e.key) {
                    case 's':
                        e.preventDefault();
                        downloadCover();
                        break;
                    case 'Enter':
                        e.preventDefault();
                        generateCover();
                        break;
                }
            }
        });
        
        // 初始化
        updatePreview();
        
        // 添加使用提示
        window.addEventListener('load', () => {
            setTimeout(() => {
                showNotification('💡 快捷键：Ctrl+S 下载，Ctrl+Enter 生成', 'info');
            }, 1000);
        });
    </script>
</body>
</html>